package com.zsjt.app.compoent.security.permission;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义权限拦截
 */
@Component("accessDeniedFilter")
public class AccessDeniedFilter implements AccessDeniedHandler {
    /**
     * 自定义权限拦截
     * @param httpServletRequest
     * @param httpServletResponse
     * @param e
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
//        System.out.println("权限不足");
        httpServletRequest.setAttribute("limitedAccess",1);
        httpServletRequest.getRequestDispatcher("/main").forward(httpServletRequest, httpServletResponse);
    }
}
